package 每日一题;

/**
 * @author 会玩的洋洋
 * https://leetcode-cn.com/problems/maximum-difference-between-increasing-elements/
 */
public class _2016_增量元素之间的最大差值 {
    public int maximumDifference(int[] nums) {
        int slow = 0, fast = 1;
        int max = -1;
        while (fast < nums.length) {
            if (nums[fast] > nums[slow]) {
                max = Math.max(max, nums[fast] - nums[slow]);
            } else if (nums[fast] < nums[slow]) {
                slow = fast;
            }
            fast++;
        }
        return max;
    }
}
